const userController = require('../controllers/userController')
const router = require('koa-router')()

router.prefix('/users')

router.get('/', async function (ctx, next) {
  ctx.body = await userController.findUsers(ctx.query)
})

router.get('/:id', async function (ctx, next) {
  ctx.body = await userController.findUser(ctx.params.id)
})

router.post('/', async (ctx, next) => {
  ctx.body = await userController.createUser(ctx.request.body)
});

router.put('/', async (ctx, next) => {
  ctx.body = await userController.deleteUser(ctx.request.body)
});

router.delete('/:id', async (ctx) => {
	ctx.body = await userController.deleteUser(ctx.params.id)
})

router.put('/:id', async (ctx) => {
	ctx.body = await userController.updateUser(ctx.request.body, ctx.params.id)
})
module.exports = router
